
package com.lzb.compressmaster.adapter;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ImageUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.basic.ProviderMultiAdapter;
import com.lzb.compressmaster.view.WatermarkImgView;

import java.util.ArrayList;
import java.util.List;

public class ImgListAdapter extends ProviderMultiAdapter<String> {

    private List<Bitmap> listBitmap = new ArrayList<>();
    private String text;

    public ImgListAdapter() {
        addItemProvider(new ImgListProvider());
    }

    public List<Bitmap> getListBitmap() {
        return listBitmap;
    }

    public void setListBitmap(List<Bitmap> listBitmap) {
        this.listBitmap = listBitmap;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
        notifyDataSetChanged();
    }

    private class ImgListProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_img_list;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String bean) {
            if (baseViewHolder.getBindingAdapterPosition() == 0) listBitmap.clear();
            ImageView ivImgListItemImg = baseViewHolder.getView(R.id.ivImgListItemImg);
            Glide.with(getContext()).load(bean)
                    .into(ivImgListItemImg);
//            ivImgListItemImg.setImageBitmap(BitmapFactory.decodeFile(bean));
//            ivImgListItemImg.setStyle(WatermarkImgView.Style.ZUO_XIE);
//            ivImgListItemImg.setWatermarkText(text);
//            new Handler().post(new Runnable() {
//                @Override
//                public void run() {
//                    listBitmap.add(ImageUtils.view2Bitmap(ivImgListItemImg));
//                }
//            });
//            listBitmap.add(ImageUtils.view2Bitmap(ivImgListItemImg));
        }
    }

}
